/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
  .name = "defaultTask",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityNormal3,
};
/* Definitions for openmv_task */
osThreadId_t openmv_taskHandle;
const osThreadAttr_t openmv_task_attributes = {
  .name = "openmv_task",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityNormal2,
};
/* Definitions for myTask */
osThreadId_t myTaskHandle;
const osThreadAttr_t myTask_attributes = {
  .name = "myTask",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for ic_cade_task */
osThreadId_t ic_cade_taskHandle;
const osThreadAttr_t ic_cade_task_attributes = {
  .name = "ic_cade_task",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityNormal2,
};
/* Definitions for dispatcher_task_tx */
osMessageQueueId_t dispatcher_task_txHandle;
const osMessageQueueAttr_t dispatcher_task_tx_attributes = {
  .name = "dispatcher_task_tx"
};
/* Definitions for openmv_task_tx */
osMessageQueueId_t openmv_task_txHandle;
const osMessageQueueAttr_t openmv_task_tx_attributes = {
  .name = "openmv_task_tx"
};
/* Definitions for ic_rx_pack */
osMessageQueueId_t ic_rx_packHandle;
const osMessageQueueAttr_t ic_rx_pack_attributes = {
  .name = "ic_rx_pack"
};
/* Definitions for led_mutexes */
osMutexId_t led_mutexesHandle;
const osMutexAttr_t led_mutexes_attributes = {
  .name = "led_mutexes"
};

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

void StartDefaultTask(void *argument);
void app_openmv_task(void *argument);
void myTask_idle(void *argument);
void app_ic_cade_task(void *argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */

  /* USER CODE END Init */
  /* Create the mutex(es) */
  /* creation of led_mutexes */
  led_mutexesHandle = osMutexNew(&led_mutexes_attributes);

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* Create the queue(s) */
  /* creation of dispatcher_task_tx */
  dispatcher_task_txHandle = osMessageQueueNew (16, sizeof(uint8_t), &dispatcher_task_tx_attributes);

  /* creation of openmv_task_tx */
  openmv_task_txHandle = osMessageQueueNew (16, sizeof(uint8_t), &openmv_task_tx_attributes);

  /* creation of ic_rx_pack */
  ic_rx_packHandle = osMessageQueueNew (16, sizeof(uint16_t), &ic_rx_pack_attributes);

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
  /* creation of defaultTask */
  defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);

  /* creation of openmv_task */
  openmv_taskHandle = osThreadNew(app_openmv_task, NULL, &openmv_task_attributes);

  /* creation of myTask */
  myTaskHandle = osThreadNew(myTask_idle, NULL, &myTask_attributes);

  /* creation of ic_cade_task */
  ic_cade_taskHandle = osThreadNew(app_ic_cade_task, NULL, &ic_cade_task_attributes);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */

  /* USER CODE BEGIN RTOS_EVENTS */
  /* add events, ... */
  /* USER CODE END RTOS_EVENTS */

}

/* USER CODE BEGIN Header_StartDefaultTask */
/**
  * @brief  Function implementing the defaultTask thread.
  * @param  argument: Not used
  * @retval None
  */
/* USER CODE END Header_StartDefaultTask */
__weak void StartDefaultTask(void *argument)
{
  /* USER CODE BEGIN StartDefaultTask */
  /* Infinite loop */
  for(;;)
  {
    vTaskDelay(1000);

  }
  /* USER CODE END StartDefaultTask */
}

/* USER CODE BEGIN Header_app_openmv_task */
/**
* @brief Function implementing the openmv_task thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_app_openmv_task */
__weak void app_openmv_task(void *argument)
{
  /* USER CODE BEGIN app_openmv_task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END app_openmv_task */
}

/* USER CODE BEGIN Header_myTask_idle */
/**
* @brief Function implementing the myTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_myTask_idle */
__weak void myTask_idle(void *argument)
{
  /* USER CODE BEGIN myTask_idle */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END myTask_idle */
}

/* USER CODE BEGIN Header_app_ic_cade_task */
/**
* @brief Function implementing the ic_cade_task thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_app_ic_cade_task */
__weak void app_ic_cade_task(void *argument)
{
  /* USER CODE BEGIN app_ic_cade_task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END app_ic_cade_task */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

/* USER CODE END Application */

